// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database();
const mycol = db.collection("postalUserInfo");

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  let {name} = event;

  function getDate(){ //定义日期格式
    let date = new Date();
    return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
  }

  let res = await mycol.add({
    data:{
      name,
      gameCount:0,
      prizeCount:0,
      time: getDate(),
      openid:wxContext.OPENID
    }
  })

  return {
    result:{
      msg:"上传成功！",
      res
    }
  }
}